import { ajaxPost } from 'api/axios'
import { HttpUrl, ERR_OK } from 'api/config'

const actions = {
  GET_TOTAL ({ commit }, type) {
    return new Promise(async resolve => {
      const url = `${HttpUrl}/${type}/total`

      const res = await ajaxPost(url)

      if (res.code === ERR_OK) {
        commit('SET_TOTAL', { key: type, value: res.data })
        resolve(true)
      } else {
        resolve(false)
      }
    })
  }
}

export default actions
